package com.gsit.expenditure.utils;

import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Utils {

	public final static String SOURCE_PATH = "/reports/InvoiceTest.jrxml";
	public final static String DEST_PATH = "/Invoice Files/PDFs";
	public final static String REPORTS_PATH = "/reports";
	public final static String DEST_FILE_NAME = "invoice.pdf";
	public final static int DEST_FILE_NAME1 =InvoiceNumberGenerator.getInstance().getCounter() ;
	public final static String FILE_EXT=".pdf";
	
	public static Date getCurrentDate() {
		//DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
		Date date = new Date();
		return date;
	}
	
	public static StringBuffer getReportsPath() {
		
		StringBuffer path = new StringBuffer(System.getProperty("user.home"));
		path.append("/");
		path.append("ExpenditureApp");
		path.append("/");
		path.append(REPORTS_PATH);
		
		File file = new File(path.toString());
		if(!file.exists())
			if(!file.mkdirs()){
				try {
					throw new Exception("Can not create file");
				} catch (Exception e) {
					e.printStackTrace();
				}
				path.append("/");
				path.append(DEST_FILE_NAME);
			}
		return path ;
	}
	

	public static StringBuffer getDestinationPath() {
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		StringBuffer path = getReportsPath();
		path.append("/");
		path.append("invoicepdf");
		path.append("/");
		path.append(dateFormat.format(getCurrentDate()));

		File file = new File(path.toString());
		if(!file.exists())
			if(!file.mkdirs()){
				try {
					throw new Exception("Can not create file");
				} catch (Exception e) {
					e.printStackTrace();
			}
				path.append("/");
				path.append(DEST_FILE_NAME1+FILE_EXT);
			}
		return path ;
	}

	public static StringBuffer getPreviewPath() {
		String FILE_NAME="invoice.pdf";
		StringBuffer path = getReportsPath();
		path.append("/");
		path.append("preview");
		File file = new File(path.toString());
		if(!file.exists())
			if(!file.mkdirs()){
				try {
					throw new Exception("Can not create file");
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		path.append("/");
		path.append(FILE_NAME);
		
		return path ;
	}

}
